#include <stdio.h>

main (void) {

	printf("Array example from K&R page 44\n");
	printf("Enter some characters and this simple program will count the occurance of all char and digits\n");

	int c, i, nwhite, other;
	int ndigit[10];

	nwhite = other = 0;

	//array needs to set its elements otherwise
	//it may be (and will be in fact) initialized
	//to some random numbers
	for (i = 0; i < 10; i++)
		ndigit[i] =0;

	//just reading until EOF is reached ctrl+d
	//once char is entered it ifs will decide what type of char
	//was just entered and increase proper count
	while ((c = getchar()) != EOF) {
		if (c >= '0' && c <= '9') {
			//check out page 45
			++ndigit[c - '0'];
			}
		else if ( c == ' ' || c == '\n' || c == '\t')
			++ nwhite;
		else
			++other;
	}

	printf("\nDigits:: ");
	for (i = 0; i < 10; i++)
		printf(" %d", ndigit[i]);

	printf("\nWhite characters:: %d, Others:: %d\n", nwhite, other);

}
